﻿using System.Text;
using System.Windows;
using PDOGenerator.Generators;
using PDOGenerator.MapTypes;

namespace PDOGenerator
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            DataContext = PM;

        }

        public GeneratorPM PM
        {
            get { return (PdoApp.Current as PdoApp).PM; }
        }

        private void saveMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Project p = PM.Project;
            if (string.IsNullOrEmpty(p.FileName))
            {
                saveAsMenuItem_Click(sender, e);
            }
            else
            {
                p.Save();
            }
        }

        private void openMenuItem_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Filter = "pdoGen (*.pdoGen)|*.pdoGen|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                PM.Project = Project.Load(ofd.FileName);
                PM.Project.FileName = ofd.FileName;
            }

        }

        private void saveAsMenuItem_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
            sfd.Filter = "pdoGen (*.pdoGen)|*.pdoGen|All Files (*.*)|*.*";

            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Project p = PM.Project;
                p.FileName = sfd.FileName;
                p.Save();
            }
        }

    }
}
